package com.pactera.madp.cp.controller.sidebar.beta;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pactera.madp.common.core.util.R;
import com.pactera.madp.cp.api.dto.beta.WorkNewsQueryDTO;
import com.pactera.madp.cp.api.em.beta.NewsStateEnum;
import com.pactera.madp.cp.api.vo.beta.InfoMorningIndexVO;
import com.pactera.madp.cp.api.vo.beta.WorkChoreographyVO;
import com.pactera.madp.cp.api.vo.beta.WorkNewsGroupVO;
import com.pactera.madp.cp.api.vo.beta.WorkOriginalVO;
import com.pactera.madp.cp.service.InfoMorningService;
import com.pactera.madp.cp.service.WorkChoreographyService;
import com.pactera.madp.cp.service.WorkNewsGroupService;
import com.pactera.madp.cp.service.WorkOriginalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @title 资讯早报-业务控制
 * @date 2022-06-15
 * @author Deming.Chang
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/info")
@Api(value = "info", tags = "资讯早报管理")
public class InfoMorningController {

    /**
     * 资讯早报-业务服务
     */
    private final InfoMorningService infoMorningService;
    /**
     * 精编资讯-业务服务
     */
    private final WorkChoreographyService choreographyService;
    /**
     * 原创资讯-业务服务
     */
    private final WorkOriginalService originalService;
    /**
     * 资讯分组-业务服务
     */
    private final WorkNewsGroupService newsGroupService;
    /**
     * 获取金融小店资讯摘要数据
     * @return 获取金融小店资讯摘要数据
     */
    @GetMapping("/summary")
    @ApiOperation(value = "获取金融小店资讯摘要数据")
    public R<String> summary(){
        return R.ok(infoMorningService.getSummary());
    }

    /**
     * 获取资讯早报首页数据
     * @return 返回早报资讯首页数据
     */
    @GetMapping("/index")
    @ApiOperation(value = "获取资讯早报首页数据")
    public R<InfoMorningIndexVO> index(){
        return R.ok(infoMorningService.getIndex());
    }

    /**
     * 获取指定资讯ID的精编资讯详情信息(含早报)
     * @param newsKey    资讯业务主键
     * @return 返回精编资讯详细信息
     */
    @GetMapping("/choreography/{newsKey}")
    @ApiOperation(value = "获取指定资讯ID的精编资讯详情信息(含早报)")
    public R<WorkChoreographyVO> getByChoreographyNewsKey(@PathVariable("newsKey") String newsKey){
        return R.ok(choreographyService.getByNewsKey(newsKey));
    }

    /**
     * 获取指定资讯ID的原创资讯(策略研究|行内新闻)
     * @param newsKey    资讯业务主键
     * @return 返回精编资讯详细信息
     */
    @GetMapping("/original/{newsKey}")
    @ApiOperation(value = "获取指定资讯ID的原创资讯(策略研究|行内新闻)")
    public R<WorkOriginalVO> getByOriginalNewsKey(@PathVariable("newsKey") String newsKey){
        return R.ok(originalService.getByNewsKey(newsKey));
    }

    /**
     * 根据分组ID获取分组信息含子分组
     * @param groupId   资讯分组ID
     * @return 返回分组ID
     */
    @GetMapping("/group/{groupId}")
    @ApiOperation(value = "根据分组ID获取分组信息含子分组")
    public R<WorkNewsGroupVO> getByGroupId(@PathVariable("groupId") Integer groupId){
        return R.ok(newsGroupService.getByGroupId(groupId));
    }

    /**
     * 精编系列分页查询
     * @param page  分页条件
     * @param dto   查询条件
     * @return
     */
    @GetMapping("/choreography/page")
    @ApiOperation(value = "精编系列分页查询")
    public R<IPage<WorkChoreographyVO>> getChoreographyPage(Page page, WorkNewsQueryDTO dto){
        dto.setState(NewsStateEnum.PUBLISHED.getState());
        return R.ok(choreographyService.getPage(page, dto));
    }

    /**
     * 原创资讯(策略研究|行内新闻)分页查询
     * @param page  分页条件
     * @param dto   查询条件
     * @return
     */
    @GetMapping("/original/page")
    @ApiOperation(value = "原创资讯(策略研究|行内新闻)分页查询")
    public R<IPage<WorkOriginalVO>> getOriginalPage(Page page, WorkNewsQueryDTO dto){
        dto.setState(NewsStateEnum.PUBLISHED.getState());
        return R.ok(originalService.getPage(page, dto));
    }

}
